using System;
using System.Runtime.CompilerServices;
using BitMango.Diagnostics;
using Holoville.HOTween;
using Holoville.HOTween.Core;
using UnityEngine;

public class GUISceneSpotlight : SingletonMonoBehaviour<GUISceneSpotlight>
{
	private static void SInit()
	{
		if (GUISceneSpotlight._spotlight == null)
		{
			GameObject original = Resources.Load("Spotlight") as GameObject;
			GUISceneSpotlight._spotlight = UnityEngine.Object.Instantiate<GameObject>(original);
			GUISceneSpotlight._spotlight.name = "spotlightTransition";
			GUISceneSpotlight._plane = GUISceneSpotlight._spotlight.transform.Find("plane").gameObject;
			GUISceneSpotlight._spot = GUISceneSpotlight._spotlight.transform.Find("spot").gameObject;
			GUISceneSpotlight._cam = GUISceneSpotlight._spotlight.transform.Find("cam").gameObject;
			GUISceneSpotlight._spotlight.transform.localPosition = Vector3.back * 150f;
			GUISceneSpotlight.UpdateScale();
		}
	}

	public static void Show(float sec, string mode = null)
	{
		GUISceneSpotlight.SInit();
		GUISceneSpotlight._spotlight.SetActive(true);
		if (mode != null && mode.Equals("StarSpotlight"))
		{
			GUISceneSpotlight._spot.GetComponent<MeshFilter>().mesh = GUISceneSpotlight.GetStarMesh();
		}
		else if (mode != null && mode.Equals("Spotlight"))
		{
			GUISceneSpotlight._spot.GetComponent<MeshFilter>().mesh = GUISceneSpotlight.GetCircleMesh();
		}
		else if (mode != null && mode.Equals("HexagonSpotlight"))
		{
			GUISceneSpotlight._spot.GetComponent<MeshFilter>().mesh = GUISceneSpotlight.GetHexagonMesh();
			GUISceneSpotlight._spot.transform.eulerAngles = Vector3.forward * 30f;
		}
		else if (mode != null && mode.Equals("Custom"))
		{
			GUISceneSpotlight._spot = GUISceneSpotlight.GetCustomGameObject();
		}
		TweenParms p_parms = new TweenParms().Prop("localScale", new Vector3(GUISceneSpotlight.amount, GUISceneSpotlight.amount, 1f));
		HOTween.From(GUISceneSpotlight._spot.transform, sec, p_parms);
	}

	public static void Hide(float sec, string mode = null)
	{
		GUISceneSpotlight.SInit();
		if (mode != null && mode.Equals("StarSpotlight"))
		{
			GUISceneSpotlight._spot.GetComponent<MeshFilter>().mesh = GUISceneSpotlight.GetStarMesh();
		}
		else if (mode != null && mode.Equals("Spotlight"))
		{
			GUISceneSpotlight._spot.GetComponent<MeshFilter>().mesh = GUISceneSpotlight.GetCircleMesh();
		}
		else if (mode != null && mode.Equals("HexagonSpotlight"))
		{
			GUISceneSpotlight._spot.GetComponent<MeshFilter>().mesh = GUISceneSpotlight.GetHexagonMesh();
			GUISceneSpotlight._spot.transform.eulerAngles = Vector3.forward * 30f;
		}
		else if (mode != null && mode.Equals("Custom"))
		{
			GUISceneSpotlight._spot = GUISceneSpotlight.GetCustomGameObject();
		}
		TweenParms tweenParms = new TweenParms().Prop("localScale", new Vector3(GUISceneSpotlight.amount, GUISceneSpotlight.amount, 1f)).Ease(EaseType.EaseInQuad);
		object transform = GUISceneSpotlight._spot.transform;
		TweenParms tweenParms2 = tweenParms;
		if (GUISceneSpotlight._003C_003Ef__mg_0024cache0 == null)
		{
			GUISceneSpotlight._003C_003Ef__mg_0024cache0 = new TweenDelegate.TweenCallback(GUISceneSpotlight.Completed);
		}
		HOTween.To(transform, sec, tweenParms2.OnComplete(GUISceneSpotlight._003C_003Ef__mg_0024cache0));
	}

	private static void Completed()
	{
		GUISceneSpotlight._spotlight.SetActive(false);
		GUISceneSpotlight._spot.transform.localScale = Vector3.zero;
	}

	private static void UpdateScale()
	{
		Vector2 screenSize = GUISceneSpotlight.GetScreenSize();
		GUISceneSpotlight.amount = Mathf.Sqrt(Mathf.Pow(screenSize.x, 2f) + Mathf.Pow(screenSize.y, 2f)) * 2f;
		GUISceneSpotlight._plane.transform.localScale = new Vector3(screenSize.x, screenSize.y, 0.1f);
	}

	private static Mesh GetStarMesh()
	{
		Mesh mesh = new Mesh();
		mesh.name = "Star Mesh";
		int num = 10;
		int[] array = new int[num * 3];
		float num2 = -360f / (float)num;
		Vector3[] array2 = new Vector3[num + 1];
		Vector3[] array3 = new Vector3[]
		{
			new Vector3(0f, 1f, 0f),
			new Vector3(0f, 0.5f, 0f)
		};
		int i = 0;
		int num3 = 1;
		int num4 = 1;
		while (i < 5)
		{
			int j = 0;
			while (j < array3.Length)
			{
				array2[num3] = Quaternion.Euler(0f, 0f, num2 * (float)(num3 - 1)) * array3[j];
				array[num4] = num3;
				array[num4 + 1] = num3 + 1;
				j++;
				num3++;
				num4 += 3;
			}
			i++;
		}
		array[array.Length - 1] = 1;
		mesh.vertices = array2;
		mesh.triangles = array;
		return mesh;
	}

	private static Mesh GetCircleMesh()
	{
		Mesh mesh = new Mesh();
		mesh.name = "Circle Mesh";
		int num = 30;
		int[] array = new int[num * 3];
		float num2 = -360f / (float)num;
		Vector3[] array2 = new Vector3[num + 1];
		Vector3 up = Vector3.up;
		int i = 1;
		int num3 = 1;
		while (i < array2.Length)
		{
			array2[i] = Quaternion.Euler(0f, 0f, num2 * (float)(i - 1)) * up;
			array[num3] = i;
			array[num3 + 1] = i + 1;
			i++;
			num3 += 3;
		}
		array[array.Length - 1] = 1;
		mesh.vertices = array2;
		mesh.triangles = array;
		return mesh;
	}

	private static Mesh GetHexagonMesh()
	{
		Mesh mesh = new Mesh();
		mesh.name = "Hexagon Mesh";
		int num = 6;
		int[] array = new int[num * 3];
		float num2 = -360f / (float)num;
		Vector3[] array2 = new Vector3[num + 1];
		Vector3 up = Vector3.up;
		int i = 1;
		int num3 = 1;
		while (i < array2.Length)
		{
			array2[i] = Quaternion.Euler(0f, 0f, num2 * (float)(i - 1)) * up;
			array[num3] = i;
			array[num3 + 1] = i + 1;
			i++;
			num3 += 3;
		}
		array[array.Length - 1] = 1;
		mesh.vertices = array2;
		mesh.triangles = array;
		return mesh;
	}

	private static GameObject GetCustomGameObject()
	{
		if (GUISceneSpotlight._spotImg == null)
		{
			GameObject original = Resources.Load("transition/spotImg") as GameObject;
			GUISceneSpotlight._spotImg = UnityEngine.Object.Instantiate<GameObject>(original);
			GUISceneSpotlight._spotImg.transform.parent = GUISceneSpotlight._spotlight.transform;
			GUISceneSpotlight._spotImg.transform.localPosition = Vector3.zero + Vector3.forward * 5f;
		}
		Debugger.Assert(GUISceneSpotlight._spotImg != null, "Not Find Resource \"transition/spotImg\"");
		return GUISceneSpotlight._spotImg;
	}

	private static Vector2 GetScreenSize()
	{
		Camera component = GUISceneSpotlight._cam.GetComponent<Camera>();
		Debugger.Assert(component != null);
		Vector3 vector = component.ViewportToWorldPoint(new Vector3(0f, 0f, component.nearClipPlane));
		Vector3 vector2 = component.ViewportToWorldPoint(new Vector3(1f, 1f, component.nearClipPlane));
		return new Vector2(vector2.x - vector.x, vector2.y - vector.y);
	}

	private static GameObject _spotlight;

	private static GameObject _plane;

	private static GameObject _spot;

	private static GameObject _spotImg;

	private static GameObject _cam;

	private const string kSpotlightTag = "spotlightTransition";

	private static float amount;

	[CompilerGenerated]
	private static TweenDelegate.TweenCallback _003C_003Ef__mg_0024cache0;
}
